package com.atguigu.utils;

import com.atguigu.pojo.User;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

public class WebUtils {
    public static  <T> T copyParamToBean(Map value, T bean){
        try {
//            User user = new User();
//            System.out.println("注入之前：" + user);
            /*
             * 把所有请求参数注入到对象中
             * */
            BeanUtils.populate(bean,value);
//            System.out.println("注入之后" + bean);

        } catch ( Exception e) {
            e.printStackTrace();
        }
        return bean;
    }
    public static int parseInt(String strInt,int defaultValue){

        try {
            return Integer.parseInt(strInt);
        } catch (NumberFormatException e) {
//            e.printStackTrace();
        }
return defaultValue;

    }

}
